<?php

/**

 * Joomla! 1.5 component Folder Space Quota

 *

 * @version $Id: folderspacequota.php 2011-01-24 10:48:13 svn $

 * @author DoggyDams

 * @package Joomla

 * @subpackage Folder Space Quota

 * @license GNU/GPL

 *

 * Control used space of specific directory

 *

* @Copyright Copyright (C) 2010 - DoggyDamss
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html 


 *

 */



// no direct access
defined('_JEXEC') or die('Restricted access');

echo '<script type="text/javascript">
function toggledir(id){
if (document.getElementById(id).style.display == "none") document.getElementById(id).style.display = "" ;
else document.getElementById(id).style.display = "none";
}
</script>';
$imgPath4 = JRoute::_('/administrator/components/com_folderspacequota/icons/quotatree.png');
$imgPath3 = JRoute::_('/administrator/components/com_folderspacequota/icons/home.png');
$imgPath2 = JRoute::_('/administrator/components/com_folderspacequota/icons/quotaf32.png');
$imgPath = JRoute::_('/administrator/components/com_folderspacequota/icons/treefold32.png');
JFactory::getDocument()->addStyleDeclaration(".icon-32-treefold { background: url($imgPath); }.icon-32-quotaf { background: url($imgPath2); }.icon-32-home { background: url($imgPath3); }.icon-48-quotatree { background: url($imgPath4); }");

JToolBarHelper::title(JText::_('Folder Space Quota'), 'quotatree.png');

$bar = & JToolBar::getInstance('toolbar');

$url3 = JRoute::_('index.php?option=com_folderspacequota&task=default&view=default');
$alt3 = JText::_( 'QUOTA_HOME');
$bar->appendButton( 'Link', 'home', $alt3, $url3);

$url2 = JRoute::_('index.php?option=com_folderspacequota&task=default&view=quota');
$alt2 = JText::_( 'QUOTA_QUOTAS');
$bar->appendButton( 'Link', 'quotaf', $alt2, $url2);

$url = JRoute::_('index.php?option=com_folderspacequota&task=default&view=list');
$alt = JText::_( 'QUOTA_CONTENTS');
$bar->appendButton( 'Link', 'treefold', $alt, $url);

JToolBarHelper::preferences('com_folderspacequota',$height='425');

require_once("../administrator/components/com_folderspacequota/class/folder_space.class.php");
$params = &JComponentHelper::getParams( 'com_folderspacequota' );
$source = $params->get( 'foldertoscan' );
$maxsize = $params->get( 'maxsize' );
if ((!$foldcolor = $params->get( 'foldcolor' ))||($params->get( 'foldcolor' ) == 'FOLD_BAR_COLOR')){$foldcolor = '#0b55c4';}
$foldprefix = $params->get( 'folderprefix' );

function SubFoldSize($source,$size,$width,$color,$prefix){
	
$params = &JComponentHelper::getParams( 'com_folderspacequota' );
$subsize = $params->get( 'subsize' );
$addsub = $params->get( 'addsubfold' );
if ((!$subcolor = $params->get( 'subcolor' ))||($params->get( 'subcolor' ) == 'SUB_BAR_COLOR')){$subcolor='#00bfbf';}
$subprefix = $params->get( 'subfolderprefix' );

	
$dir_handle = @opendir($source);

$folders = array();
	while ($folder = readdir($dir_handle)) {
		if($folder!="." && $folder!="..") {
		$dir =$source.'/'.$folder;
			if (is_dir($dir)) {$folders[] = $folder;}
		}
	}
sort ($folders); reset ($folders);
	
echo '<br/><ul>';
	
	foreach ($folders as $folder){
	$data = array(
	'total'=>$size,
	'max_height'=>50,
	'max_width'=>$width,
	'axis'=> 'vertical',
	'bar_name'=> 'Quota',
	'dir'=> $source.'/'.$folder,
	'empty_color'=>'#F1F2F3',
	'full_color'=>$color,
	'float'=>'left',
	'var_dump'=> false
	);

	echo '<br/><li style="font-size:12px;font-weight:bold;text-decoration:underline;"><a href="javascript:void();" onclick="toggledir(\''.$source.'/'.$folder.'\');">'.$prefix.$folder.'</a></li>';
	echo "<div id='".$source.'/'.$folder."' style='display:none;clear:both;'><br/>";
	$fldr = new handle();
	$fldr->create($data);
		if ($addsub == 0) echo '<div style="clear:both"></div>';
		else {
			if ($subsize){
			echo '<div style="clear:both"></div>';
			SubFoldSize($source.'/'.$folder,$subsize,8,$subcolor,$subprefix);
			} else {
			echo '<br/><div style="font-size:14px;text-align:center;"><strong>'.JText::_( 'SIZE_ERROR').'</strong><br/>'.JText::_( 'SIZE_ERROR_').'</div><br/>';}
		}
	echo '</div><br/>';
	}
echo '</ul>';
closedir($dir_handle);
}

if ($source = $params->get( 'foldertoscan' )){
$badstrings = array("../","./");
$source = str_replace($badstrings,"",$source);
if (substr($source,0,1) == '/') $source = substr($source,1) ;
	if ($maxsize = $params->get( 'maxsize' )){
		if (opendir("../$source")) {
		echo '<br/><div><span style="font-size:14px;font-weight:bold;">'.JText::_( 'QUOTA_DIR').' : '.$source.'</span> <span style="font-size:12px;">&nbsp;&nbsp;(&lt;root&gt; <i>/'.$source.'</i>)</span></div>';
			SubFoldSize("../$source",$maxsize,15,$foldcolor,$foldprefix); echo '<br/>';
		} else { echo '<br/><div style="font-size:14px;text-align:center;"><strong>'.JText::_( 'PATH_ERROR').'</strong><br/>'.JText::_( 'PATH_ERROR_').'</div><br/>'; }
	} else { echo '<br/><div style="font-size:14px;text-align:center;"><strong>'.JText::_( 'SIZE_ERROR').'</strong><br/>'.JText::_( 'SIZE_ERROR_').'</div><br/>'; }
} else { echo '<br/><div style="font-size:14px;text-align:center;"><strong>'.JText::_( 'CONF_ERROR').'</strong><br/>'.JText::_( 'CONF_ERROR_').'</div><br/>'; }


?>
